﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：MessageBoardList.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：显示留言板信息
 * 作者：侯建
 * 创建日期：2011.04.05
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.Common.JSON;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Jxym.wlkc2011.Module.Default.server.MessageBoard
{
    public class MyCommunity : model.Community
    {
        public string ReplyContent { get; set; }
    }

    public partial class MessageBoardList : System.Web.UI.Page
    {
        MsSqlDal<model.Community> iCom = new MsSqlDal<model.Community>();
        //MsSqlDal<model.Community> iCom = new MsSqlDal<model.Community>();
        IList<MyCommunity> Comlist = new List<MyCommunity>();
        PageBean pb = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["limit"] != null && Request.Params["start"] != null)
            {
                    pb = new PageBean();
                    IList<model.Community> list = iCom.GetPageList("CommunityType=0 and PrantID=0", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                    Comlist.Clear();
                    foreach (model.Community info in list)
                    {
                        Comlist.Add(GetMyCommunity(info));
                    }
                    pb.Count = iCom.GetPageCount("CommunityType=0 and PrantID=0", null);
                    pb.List = Comlist;
                    var a = JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter());
                    Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
            }
            else
            {
                Response.Write("{'Count':0,'List':[]}");
            }
        }

        private MyCommunity GetMyCommunity(model.Community info)
        {
            model.Community myinfo = iCom.GetModel("PrantID=" + info.ID, null);
            MyCommunity info2 = new MyCommunity();
            info2.AddTime = info.AddTime;
            info2.ClassID = info.ClassID;
            info2.CommunityType = info.CommunityType;
            info2.ContentText = info.ContentText;
            info2.ID = info.ID;
            info2.PrantID = info.PrantID;
            info2.Title = myinfo != null ? "<b>" + info.Title + "</b>[已回复]" : info.Title;
            info2.ReplyContent = myinfo != null ? myinfo.ContentText : "暂无回复";
            info2.AddUser = MyGet.GetUserInfoByID(info.AddUser).Name;
            return info2;
        }
    }
}